package com.zhangzhan.exception;

import com.zhangzhan.domain.commcon.ResponseResult;
import com.zhangzhan.domain.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 张一恒
 * @version 1.0
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(MySystemException.class)
    public ResponseResult systemException(MySystemException e) {
        log.info("异常捕获消息 {} ", e);
        //从异常对象中获取提示信息封装返回
        return ResponseResult.errorResult(e.getCode(), e.getMsg());
    }

    @ExceptionHandler
    public ResponseResult exception(Exception e) {
        log.info("异常捕获消息 {} ", e);
        //从异常对象中获取提示信息封装返回
        return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR.getCode(), e.getMessage());
    }
}
